﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Core.Web;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using FineUIPro;

namespace CanDoo.Oil.WebApp.UserControls
{
    public partial class SelectCustomer : UserControlBase<ICustomerContract, Customer>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SelectCustomerControl_GridList.EnableMultiSelect = EnableMultiSelect;
                SelectCustomerControl_GridList.KeepCurrentSelection = EnableMultiSelect;
                InitGrid();
            }
        }

        protected override void InitControls()
        {
            this._GridList = SelectCustomerControl_GridList;
            this._SearchKey = SearchKey;
        }

        protected override void SetSelector()
        {
            this.Selector = p => new
            {
                p.CardNo,
                p.Sex,
                p.MobilePhone,
                p.ImageUrl,
                p.CardBank,
                p.CardName,
                p.Province,
                p.City,
                p.Area,
                p.Street,
                p.Address,
                p.CustomerLevel,
                p.CustomerLevelId,
                p.CardType,
                p.LimitProduct,
                p.LimitProductId,
                p.Balance,
                p.TotalAmount,
                p.OnLinePayMoney,
                p.CostedMoney,
                p.CashBackAmount,
                p.Integral,
                p.ServiceCenter,
                p.ServiceCenterId,
                p.Parent,
                p.ParentId,
                p.IsOnline,
                p.IsLocked,
                p.StateUpdateTime,
                p.Status,
                p.Activate,
                p.ActivateId,
                p.ActivateTime,
                p.Remark,
                p.Id,
                p.Name
            };
        }


        protected override void Search()
        {
            var key = SearchKey.GetValue();
            if(key.IsNullOrEmpty() == false)
            {
                Filter = Filter.And(p => p.Name.Contains(key));
            }
            //base.Search();
        }
    }
}

